import {hiprint} from "../../../hiprint";

export default function (options) {
    // 以 defaultElementTypeProvider 为例
    // 这里可以理解成 返回了一个 带有 addElementTypes 的 可以传入 options 去实例化的对象。
    // 如: test.js 这里的 context, 是内部去传的。
    // let test = new test(options), test.addElementTypes(context);
    let addElementTypes = function (context) {
        // 移除 旧的 defaultModule "元素"类型, 以避免重复
        context.removePrintElementTypes('sendBillModule');
        // 添加 "元素"类型
        context.addPrintElementTypes('sendBillModule', [
            // PrintElementTypeGroup 分组// 如果使用 hiprint.PrintElementTypeManager.build('.hiprintEpContainer2', "defaultModule") 这里会渲染这个 "常规" 分组名称
            new hiprint.PrintElementTypeGroup('表头', [
                {
                    tid: 'sendBillModule.titleLog', title: '单据logo', data: '', type: 'image',
                    options: {field: 'titleLog', width: 40, height: 40, fit: 'contain', hideTitle: true}
                },
                {
                    tid: "sendBillModule.titleName", title: '公司', data: '傲视易用', type: 'text',
                    options: {field: 'titleName', testData: '傲视易用', height: 17, fontSize: 16.5, fontWeight: 700, lineHeight: 17, textAlign: 'right', hideTitle: true}
                },
                {
                    tid: 'sendBillModule.headerName', title: '单据抬头', data: '发货单据', type: 'text',
                    options: {field: 'headerName', testData: '发货单据', height: 17, fontSize: 16.5, fontWeight: 700, lineHeight: 17, textAlign: 'left', hideTitle: true}
                },
            ]),
            new hiprint.PrintElementTypeGroup('单据', [
                {
                    tid: 'sendBillModule.voucheCode', title: '单据编号', type: 'text',
                    options: {field: 'voucheCode', testData: 'XS888888888', height: 16, fontSize: 6.75, textAlign: "left", "borderBottom": "solid", textContentVerticalAlign: "middle"}
                },
                {
                    tid: 'sendBillModule.voucheDate', title: '发货日期', type: 'text',
                    options: {field: 'voucheDate', testData: '2024-08-29', height: 16, fontSize: 6.75, textAlign: "left", "borderBottom": "solid", textContentVerticalAlign: "middle"},
                    formatter: function (title, value, options, templateData, target, paperNo) {
                        return value ? value.substring(0, 10) : value;
                    }
                },
                {
                    tid: 'sendBillModule.driverName', title: '发货司机', type: 'text',
                    options: {field: 'driverName', testData: '发货司机', height: 16, fontSize: 6.75, textAlign: "left", "borderBottom": "solid", textContentVerticalAlign: "middle"}
                },
                {
                    tid: 'sendBillModule.workerJson', title: '装车工人', type: 'text',
                    options: {field: 'workerJson', testData: '装车工人', height: 16, fontSize: 6.75, textAlign: "left", "borderBottom": "solid", textContentVerticalAlign: "middle"}
                },
                {
                    tid: 'sendBillModule.stockWorkerJson', title: '备货工人', type: 'text',
                    options: {field: 'stockWorkerJson', testData: '备货工人', height: 16, fontSize: 6.75, textAlign: "left", "borderBottom": "solid", textContentVerticalAlign: "middle"}
                },
                {
                    tid: 'sendBillModule.barcodeWorkerJson', title: '条码工人', type: 'text',
                    options: {field: 'barcodeWorkerJson', testData: '条码工人', height: 16, fontSize: 6.75, textAlign: "left", "borderBottom": "solid", textContentVerticalAlign: "middle"}
                },
                {
                    tid: 'sendBillModule.otherCharges', title: '其他费用', type: 'text',
                    options: {field: 'otherCharges', testData: 0.00, height: 16, fontSize: 6.75, textAlign: 'left', "borderBottom": "solid", textContentVerticalAlign: 'middle'}
                },
                {
                    tid: 'sendBillModule.updatedTime', title: '操作日期', type: 'text',
                    options: {field: 'updatedTime', testData: '操作日期', height: 16, fontSize: 6.75, textAlign: "left", "borderBottom": "solid", textContentVerticalAlign: "middle"}
                },
                {
                    tid: 'sendBillModule.createdName', title: '制单人', type: 'text',
                    options: {field: 'createdName', testData: '制单人', height: 16, fontSize: 6.75, textAlign: "left", "borderBottom": "solid", textContentVerticalAlign: "middle"}
                },
                {
                    tid: 'sendBillModule.auditorName', title: '审核人', type: 'text',
                    options: {field: 'auditorName', testData: '审核人', height: 16, fontSize: 6.75, textAlign: "left", "borderBottom": "solid", textContentVerticalAlign: "middle"}
                },
                {
                    tid: 'sendBillModule.auditorTime', title: '审核日期', type: 'text',
                    options: {field: 'auditorTime', testData: '审核日期', height: 16, fontSize: 6.75, textAlign: "left", "borderBottom": "solid", textContentVerticalAlign: "middle"}
                },
                {
                    tid: 'sendBillModule.warehouse', title: '库管', type: 'text',
                    options: {field: 'warehouse', testData: '库管', height: 16, fontSize: 6.75, textAlign: "left", "borderBottom": "solid", textContentVerticalAlign: "middle"}
                },
                {
                    tid: 'sendBillModule.doorkeeper', title: '门卫', type: 'text',
                    options: {field: 'doorkeeper', testData: '门卫', height: 16, fontSize: 6.75, textAlign: "left", "borderBottom": "solid", textContentVerticalAlign: "middle"}
                },
                {
                    tid: 'sendBillModule.remark', title: '备注', type: 'longText',
                    options: {field: 'remark', testData: '备注', width: 560, height: 17, fontSize: 6.75, textAlign: "left", textContentVerticalAlign: "middle"}
                },
                {
                    tid: 'sendBillModule.sendBottom', title: '底部信息', type: 'longText',
                    options: {field: 'sendBottom', testData: '底部信息', width: 560, height: 17, fontSize: 6.75, textAlign: "left", textContentVerticalAlign: "middle"}
                }
            ]),
            new hiprint.PrintElementTypeGroup('单据明细', [
                {
                    tid: 'sendBillModule.details', title: '单据明细', type: 'table',
                    editable: true,
                    columnDisplayEditable: true,//列显示是否能编辑
                    columnDisplayIndexEditable: true,//列顺序显示是否能编辑
                    columnTitleEditable: true,//列标题是否能编辑
                    columnResizable: true, //列宽是否能调整
                    columnAlignEditable: true,//列对齐是否调整
                    isEnableEditField: true, //编辑字段
                    isEnableContextMenu: true, //开启右键菜单 默认true
                    isEnableInsertRow: true, //插入行
                    isEnableDeleteRow: true, //删除行
                    isEnableInsertColumn: true, //插入列
                    isEnableDeleteColumn: true, //删除列
                    isEnableMergeCell: true, //合并单元格
                    options: {
                        field: 'details',
                        tableFooterRepeat: 'page',
                        tableHeaderRepeat: 'page',
                        coordinateSync: false,
                        widthHeightSync: false,
                        tableBorder: 'border',
                        tableHeaderBorder: 'border',
                        tableHeaderCellBorder: 'border',
                        tableBodyRowBorder: 'border',
                        tableBodyCellBorder: 'border',
                        tableFooterBorder: 'border',
                        tableFooterCellBorder: 'border',
                        tableHeaderFontWeight: 700,
                        fields: [{text: '序号', field: 'index'}, {text: '仓库', field: 'wareHouseName'}, {text: '生产号', field: 'batchNo'},
                            {text: '产品规格', field: 'goodsSpecName'}, {text: '货位', field: 'cargoSpaceName'}, {text: '体积', field: 'volume'},
                            {text: '存货类别', field: 'categoryName'}, {text: '客户', field: 'partnerName'}, {text: '销售号', field: 'saleSerialCode'},
                            {text: '单位', field: 'unit'}, {text: '特价', field: 'isOnSaleName'}, {text: '订货号', field: 'orderSerialCode'},
                            {text: '供应型号', field: 'goodsModel'}, {text: '条码费', field: 'barcodeCharges'}, {text: '存货类型', field: 'goodsTypeName'},
                            {text: '存货', field: 'goodsName'}, {text: '重量', field: 'weight'}, {text: '规格', field: 'specName'},
                            {text: '颜色', field: 'colourName'}, {text: '标准', field: 'standard'}, {text: '方向', field: 'direction'},
                            {text: '尺寸', field: 'size'}, {text: '总件数', field: 'totalNum'}, {text: '系数', field: 'ratio'}, {text: '件数', field: 'num'},
                            {text: '数量', field: 'qty'}, {text: '物流单号', field: 'trackingNum'}, {text: '备注', field: 'remark'},
                            {text: '装车费', field: 'loadCharges'}, {text: '物流电话', field: 'phone'}, {text: '物流', field: 'company'},
                            {text: '运费', field: 'freightCharges'}, {text: '物流区域', field: 'areaName'}, {text: '发货地址', field: 'deliveryAddress'},
                            {text: '收货地址', field: 'receiveAddress'}, {text: '审核备注', field: 'auditRemark'}, {text: '收货人', field: 'receiver'},
                            {text: '收货电话', field: 'mobile'}, {text: '订单备注1', field: 'orderRemark1'}, {text: '订单备注2', field: 'orderRemark2'},
                            {text: '订单注释', field: 'orderRemark3'}, {text: '合同号', field: 'contractNo'}, {text: '订货日期', field: 'orderVoucheDate'}]
                    },
                    columns: [
                        [
                            {title: '序号', field: 'index', width: 30, checked: true, fixed: false, align: 'center', halign: 'center'},
                            {title: '订货号', field: 'orderSerialCode', width: 67.5, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '生产号', field: 'batchNo', width: 60, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '仓库', field: 'wareHouseName', checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '货位', field: 'cargoSpaceName', width: 45, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '存货类别', field: 'categoryName', width: 60, checked: false, fixed: false, align: 'left', halign: 'center'},
                            {title: '存货类型', field: 'goodsTypeName', width: 25.5, checked: false, fixed: false, align: 'left', halign: 'center'},
                            {title: '客户', field: 'partnerName', width: 67.5, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '供应型号', field: 'goodsModel', checked: false, fixed: false, align: 'left', halign: 'center'},
                            {title: '合同号', field: 'contractNo', width: 90, checked: false, fixed: false, align: 'left', halign: 'center'},
                            {title: '销售号', field: 'saleSerialCode', width: 90, checked: false, fixed: false, align: 'left', halign: 'center'},
                            {title: '产品规格', field: 'goodsSpecName', checked: false, fixed: false, align: 'left', halign: 'center'},
                            {title: '存货', field: 'goodsName', width: 67.5, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '规格', field: 'specName', width: 90, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '颜色', field: 'colourName', width: 37.5, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '标准', field: 'standard', width: 52.5, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '方向', field: 'direction', width: 37.5, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '特价', field: 'isOnSaleName', width: 37.5, checked: true, fixed: false, align: 'center', halign: 'center'},
                            {title: '单位', field: 'unit', width: 45, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '尺寸', field: 'size', width: 37.5, checked: true, fixed: false, align: 'center', halign: 'center',
                                tableSummaryTitle: false, tableSummary: 'sum', tableSummaryNumFormat: 2},
                            {title: '系数', field: 'ratio', width: 45, checked: true, fixed: false, align: 'center', halign: 'center',
                                tableSummaryTitle: false, tableSummary: 'sum', tableSummaryNumFormat: 2},
                            {title: '体积', field: 'volume', width: 49.5, checked: true, fixed: false, align: 'left', halign: 'center',
                                tableSummaryTitle: false, tableSummary: 'sum', tableSummaryNumFormat: 2},
                            {title: '重量', field: 'weight', width: 37.5, checked: true, fixed: false, align: 'center', halign: 'center',
                                tableSummaryTitle: false, tableSummary: 'sum', tableSummaryNumFormat: 2},
                            {title: '数量', field: 'qty', width: 37.5, checked: true, fixed: false, align: 'center', halign: 'center',
                                tableSummaryTitle: false, tableSummaryNumFormat: 2},
                            {title: '件数', field: 'num', width: 37.5, checked: true, fixed: false, align: 'center', halign: 'center'},
                            {title: '总件数', field: 'totalNum', width: 37.5, checked: true, fixed: false, align: 'center', halign: 'center',
                                tableSummaryTitle: false, tableSummary: 'sum', tableSummaryNumFormat: 2},
                            {title: '运费', field: 'freightCharges', width: 60, checked: true, fixed: false, align: 'center', halign: 'center',
                                tableSummaryTitle: false, tableSummary: 'sum', tableSummaryNumFormat: 2},
                            {title: '装车费', field: 'loadCharges', width: 60, checked: true, fixed: false, align: 'center', halign: 'center',
                                tableSummaryTitle: false, tableSummary: 'sum', tableSummaryNumFormat: 2},
                            {title: '条码费', field: 'barcodeCharges', width: 67.5, checked: true, fixed: false, align: 'center', halign: 'center',
                                tableSummaryTitle: false, tableSummary: 'sum', tableSummaryNumFormat: 2},
                            {title: '备注', field: 'remark', width: 150, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '物流单号', field: 'trackingNum', width: 60, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '物流电话', field: 'phone', width: 64.5, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '物流', field: 'company', width: 90, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '物流区域', field: 'areaName', width: 75, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '发货地址', field: 'deliveryAddress', width: 90, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '收货地址', field: 'receiveAddress', checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '收货人', field: 'receiver', width: 67.5, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '收货电话', field: 'mobile', width: 60, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '审核备注', field: 'auditRemark', width: 150, checked: false, fixed: false, align: 'left', halign: 'center'},
                            {title: '订单备注1', field: 'orderRemark1', width: 75, checked: true, fixed: false, align: 'left', halign: 'center'},
                            {title: '订单备注2', field: 'orderRemark2', width: 75, checked: false, fixed: false, align: 'left', halign: 'center'},
                            {title: '订单注释', field: 'orderRemark3', width: 150, checked: false, fixed: false, align: 'left', halign: 'center'},
                            {title: '订货日期', field: 'orderVoucheDate', width: 67.5, checked: false, fixed: false, align: 'left', halign: 'center'}
                        ]
                    ],
                    footerFormatter: function (options, rows, data, currentPageGridRowsData) {
                        if (data && data['totalAmount']) return `<td colspan="100">大写金额: ${data.totalAmount}</td>`;
                        return `<td colspan="100">大写金额: </td>`;
                    }
                }
            ]),
            new hiprint.PrintElementTypeGroup('常规', [
                {tid: "sendBillModule.text", title: "文本", data: "", type: "text"},
                {tid: "sendBillModule.image", title: "图片", data: "", type: "image"},
                {tid: "sendBillModule.longText", title: "长文", data: "155123456789", type: "longText"},
                {tid: "sendBillModule.customText", title: "自定义文本", customText: "自定义文本", custom: true, type: "text"}
            ]),
            new hiprint.PrintElementTypeGroup("辅助", [
                {tid: 'sendBillModule.hline', title: '横线', type: 'hline'},
                {tid: 'sendBillModule.vline', title: '竖线', type: 'vline'},
                {tid: 'sendBillModule.rect', title: '矩形', type: 'rect'},
                {tid: 'sendBillModule.oval', title: '椭圆', type: 'oval'},
                {tid: 'sendBillModule.barcode', title: '条形码', type: 'barcode',},
                {tid: 'sendBillModule.qrcode', title: '二维码', type: 'qrcode',}
            ])
        ])
    }

    return {addElementTypes: addElementTypes}
}
